package com.bt.lms.dao.servise.impl;

import com.bt.lms.constant.BOConstant;
import com.bt.lms.entity.StuBasicInfo;
import com.bt.lms.dao.servise.StuBasicInfoDao;
import com.bt.lms.utils.DriverUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.time.LocalDate;
public class StuBasicInfoDaoImpl implements StuBasicInfoDao {
    @Override
    public boolean updateBasicInfo(String sql, StuBasicInfo stuBasicInfo,Long id) throws SQLException {
        String no = stuBasicInfo.getNo();
        String name = stuBasicInfo.getName();
        Integer sex = stuBasicInfo.getSex();
        LocalDate birthTime = stuBasicInfo.getBirthTime();
        String nativePlace = stuBasicInfo.getNativePlace();
        String nation = stuBasicInfo.getNation();
        String birthplace = stuBasicInfo.getBirthplace();
        Integer idType = stuBasicInfo.getIdType();
        String idCard = stuBasicInfo.getIdCard();
        Integer maritalStatus = stuBasicInfo.getMaritalStatus();
        Integer politicsStatus = stuBasicInfo.getPoliticsStatus();

        Connection conn = DriverUtils.Driver();
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1,no);
        ps.setString(2,name);
        ps.setInt(3,sex);
        ps.setString(4, String.valueOf(birthTime));
        ps.setString(5,nativePlace);
        ps.setString(6,nation);
        ps.setString(7,birthplace);
        ps.setInt(8,idType);
        ps.setString(9,idCard);
        ps.setInt(10,maritalStatus);
        ps.setInt(11,politicsStatus);
        ps.setLong(12,id);

        int i = ps.executeUpdate();


        //关闭资源
        ps.close();
        conn.close();

        return true;
    }
    public boolean updatePictureInfo(String sql, String path,Long id) throws SQLException {
        Connection conn = DriverUtils.Driver();
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1,path);
        ps.setInt(2,BOConstant.STU_BASIC_INFO_DELETED_PICTURE_NO);
        ps.setLong(3,id);
        int i = ps.executeUpdate();

        //关闭资源
        ps.close();
        conn.close();

        return true;
    }

    @Override
    public boolean deletePictureInfo(String sql,Long id) throws SQLException {
        Connection conn = DriverUtils.Driver();
        PreparedStatement ps = conn.prepareStatement(sql);

        ps.setInt(1, BOConstant.STU_BASIC_INFO_DELETED_PICTURE_YES);
        ps.setLong(2,id);
        int i = ps.executeUpdate();

        //关闭资源
        ps.close();
        conn.close();
        return true;
    }
    @Override
    public boolean updateExtendInfo(String sql, StuBasicInfo stuBasicInfo,Long id) throws SQLException {

        String englishName = stuBasicInfo.getEnglishName();
        String namePhoneticize = stuBasicInfo.getNamePhoneticize();
        String formerName = stuBasicInfo.getFormerName();
        Integer faith = stuBasicInfo.getFaith();
        String nationality = stuBasicInfo.getNationality();
        Integer isAlien = stuBasicInfo.getIsAlien();
        Integer physicalCondition = stuBasicInfo.getPhysicalCondition();
        Integer bloodType = stuBasicInfo.getBloodType();
        LocalDate startIDCardValidity = stuBasicInfo.getStartIDCardValidity();
        LocalDate stopIDCardValidity = stuBasicInfo.getStopIDCardValidity();
        Integer onlyChild = stuBasicInfo.getOnlyChild();

        //获取连接
        Connection conn = DriverUtils.Driver();
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1,englishName);
        ps.setString(2,namePhoneticize);
        ps.setString(3,formerName);
        ps.setInt(4,faith);
        ps.setString(5,nationality);
        ps.setInt(6,isAlien);
        ps.setInt(7,physicalCondition);
        ps.setInt(8,bloodType);
        ps.setString(9, String.valueOf(startIDCardValidity));
        ps.setString(10, String.valueOf(stopIDCardValidity));
        ps.setInt(11,onlyChild);
        ps.setLong(12,id);

        int i = ps.executeUpdate();

        //关闭资源
        ps.close();
        conn.close();

        return true;
    }
}
